package com.officeFactory;

import com.officeFactory.officeformat.ExcelForPDF;
import com.officeFactory.officeformat.WordForPDF;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangg on 2017/12/5.
 */
public class OfficeFactoryMain<T> {

    public static final int WORD_PDF = OfficeSaveFormat.W_PDF;
    public static final int EXCEL_PDF = OfficeSaveFormat.E_PDF;
    public static Map<Integer, Class> config = new HashMap<Integer, Class>();

    static {
        config.put(WORD_PDF, WordForPDF.class);
        config.put(EXCEL_PDF, ExcelForPDF.class);

    }

    public static OfficeFactoryBuilder getfactory(int name) {
        try {
            //通过反射创建builder对象
            Object o = config.get(name).newInstance();
            if (o instanceof OfficeFactoryBuilder)
                return (OfficeFactoryBuilder) o;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return null;
    }
}
